﻿using CoreAudioApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABELGX
{
    public class Volume
    {
        MMDevice device;
        public Volume()
        {
            MMDeviceEnumerator devEnum = new MMDeviceEnumerator();
            device = devEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
        }
        /// <summary>
        /// 获取当前音量
        /// </summary>
        public int Current
        {
            get => Convert.ToInt32(device.AudioEndpointVolume.MasterVolumeLevelScalar * 100.0f);
        }
        /// <summary>
        /// 设置音量
        /// </summary>
        public void SetVolume(int value)
        {
            if (value < 0) device.AudioEndpointVolume.MasterVolumeLevelScalar = 0 / 100.0f;
            else if (value > 100) device.AudioEndpointVolume.MasterVolumeLevelScalar = 100 / 100.0f;
            else device.AudioEndpointVolume.MasterVolumeLevelScalar = value / 100.0f;
        }
    }
}
